/*
** label.c for asm in /home/espiau_m/Code/proj-kw/asm/compiler
** 
** Made by marc-alexandre espiaut
** Login   <espiau_m@epitech.net>
** 
** Started on  Sat Dec 15 22:32:08 2012 marc-alexandre espiaut
** Last update Sun Dec 16 14:34:30 2012 thomas nadalie
*/

void	put_in_label_list(t_label **label, char *str, int *buff)
{
  t_label	*elem;

  if ((elem = malloc(sizeof(t_label))) == NULL)
    my_error(0, 0, "Can't perform malloc.\n", 1);
  elem->name = my_strdup(str);
  elem->position = my_strlen(buff);
  *label = elem;
}

void	is_label(t_label **label, char *str, int *buff)
{
  int	i;

  i = my_strlen(str);
  if (str[--i] == LABEL_CHAR)
    {
      put_in_label_list(label, str, buff);
    }
}

void		write_label(t_label **label, char *str, int i, int *output)
{
  t_label	*tmp;
  int		result;

  *tmp = *label;
  while (tmp != NULL)
    {
      if (strcmp (str, tmp->name) == 0)
	{
	  result = strlen(output) - tmp->position;
	  my_be_write(output, result, DIR_SIZE);
	  return ;
	}
      tmp = tmp->next;
    }
}
